layui.extend({
    'commonMock': 'mock/common'
}).define(['commonMock', 'http', 'apiCommon', 'utils', 'filters'], function (exports) {
    var request = layui.http.service,
        upload = layui.http.upload,
        commonMock = layui.commonMock,
        api = layui.apiCommon,
        utils = layui.utils,
        filters = layui.filters;
    commonMock();
    var commonServices = {

        /**
         * @author: ares
         * @date: 2020/2/15 16:22
         * @description: 获取侧边菜单数据
         * @param {string}mainMenuId  主菜单id
         * @param {string}roleId  角色id
         */
        getSideMenuService: function (mainMenuId,roleId) {
            var params = {id: mainMenuId,roleId: roleId}
            return request(api.getSideMenu, {params: params})
        },

        /**
         * @author: ares
         * @date: 2020/2/17 15:24
         * @description: 获取emr信息
         * @param {string}id  emrId
         * @param {string}referralId  转诊id
         * @param {string}number     病例号
         * @param {object}$wrap      信息容器
         */
        getEmrInfoService: function (id, referralId, number, $wrap) {
            var params = {
                id: id,
                referralId: referralId,
                number: number,
            };
            return request(api.getEmrInfo, {params: params}).then(function (res) {
                var data = res.data,
                    $fragment = $(document.createDocumentFragment());
                $fragment.append('<b class="ares-mr-lg">患者编号：' + data.number || '-' + '</b>')
                $fragment.append('<b class="ares-mr-lg">姓名：' + data.patient.name + '</b>')
                $fragment.append('<b class="ares-mr-lg">性别：' + filters.sexFormat(data.patient.sex) + '</b>')
                $fragment.append('<b class="ares-mr-lg">年龄：' + filters.ageFormat(data.patient.birthday) + '</b>')
                $fragment.append('<b class="ares-mr-lg">医保类型：' + filters.insuranceTypeFormat(data.insurance_type) + '</b>')
                if ($wrap) {
                    $wrap.empty().append($fragment);
                    return data;
                } else {
                    return {
                        fragment: $fragment,
                        data: data
                    }
                }
                return res;
            })
        },

        /**
         * @author: ares
         * @date: 2019/8/20 15:56
         * @description: 上传图片
         * @param {object}file
         * @param {object}otherData    提交到服务器的额外数据
         * @param {object}serviceConfig  上传服务配置
         * @returns {Promise.<TResult>|*}
         */
        uploadImgService: function (file, otherData, serviceConfig) {
            otherData = Object.prototype.toString.call(otherData) == '[object Object]' ? otherData : {};
            serviceConfig = Object.prototype.toString.call(serviceConfig) == '[object Object]' ? serviceConfig : {};
            var data = new FormData()
            data.append('file', file)
            if (Object.keys(otherData).length) {
                Object.keys(otherData).forEach(item => {
                    data.append(item, otherData[item])
                })
            }
            return upload(api.uploadImg, $.extend({method: 'post', params: otherData, data},serviceConfig));
            // return upload(api.uploadImg, {method: 'post', data: data});
        },

        /**
         * @author: ares
         * @date: 2021/3/19 14:20
         * @description: 根据转诊医院id查询转诊患者
         * @param {string}hospitalId   转诊医院id
         * @returns {Promise.<TResult>}
         */
        getTransferDoctorService: function (hospitalId) {
            var params = {hospitalId: hospitalId};
            return request(api.getTransferDoctor, {params: params})
        }
}

    exports("commonServices", commonServices);
})